package baptizeattribute.event;

import baptizeattribute.data.Data;
import baptizeattribute.inventory.Inv;
import baptizeattribute.utils.Tools;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

public class PlayerQuit implements Listener {
    @EventHandler
    public void event(PlayerQuitEvent e){
        Player p = e.getPlayer();
        if (Data.guiFlag.get(p.getUniqueId())!=null && Data.guiFlag.get(p.getUniqueId())){
            Inventory iv = Inv.playerIv.get(p.getUniqueId());
            if (iv.getItem(Inv.itemOneID)!=null){
                ItemStack item = iv.getItem(Inv.itemOneID);
                Tools.addPlayerByItem(p,item,item.getAmount());
            }
            if (iv.getItem(Inv.itemTwoID)!=null){
                ItemStack item = iv.getItem(Inv.itemTwoID);
                Tools.addPlayerByItem(p,item,item.getAmount());
            }
        }
    }
}
